var DAO=require('./DAO')
var communityDAO={
  addComment:function(comment,callback){
     DAO('insert into `comment`(commentContent,commentTime,userId) values(?,now(),?) ',[comment.commentContent,comment.userId],function(err,results){
         if(err){
             callback(err,null)
         }else{
             callback(null,results)
         }
     })
  },
  getList:function(callback){
      DAO('select `comment`.*,userinfos.* from `comment`,userinfos where `comment`.userId=userinfos.userId',function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
      })
  },
  getCommnetList:function(userId,callback){
    DAO('select `comment`.*,userinfos.* from `comment`,userinfos where `comment`.userId=userinfos.userId and userinfos.userId=?',[userId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  },
  getCommentDetails:function(commentId,callback){
    DAO('select * from `comment` where commentId=?',[commentId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  },
  delComment:function(commentId,callback){
    DAO(' delete from `comment` where commentId=? ',[commentId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  },
  addReply:function(reply,callback){
    DAO(' insert into reply(replyContent,replyTime,replyUserId,toCommentId) values(?,now(),?,?)',[reply.replyContent,reply.userId,reply.commentId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  },
  getReply:function(commentId,callback){
    DAO(' select * from reply where toCommentId=?',[commentId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  },
  delReply:function(commentId,callback){
    DAO(' delete from reply where toCommentId=?',[commentId],function(err,results){
        if(err){
            callback(err,null)
        }else{
            callback(null,results)
        }
    })
  }
}

module.exports=communityDAO
